package view;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

//@author A0081236L
public class CLIHelpPanel extends BackgroundPanel{
		
		public CLIHelpPanel(){
			setLayout(new BorderLayout(0, 0));
			try {
				File input = new File("src/storage/CLI Help.txt");
				String string;
					string = deserializeString(input);
				JTextArea textArea = new JTextArea(string);
				textArea.setEditable(false);
				textArea.setWrapStyleWord(true);
				textArea.setLineWrap(true);
				textArea.setVisible(true);
	
				JScrollPane scroll = new JScrollPane(textArea);
				add(scroll, BorderLayout.CENTER);

			} catch (IOException e) {
				JOptionPane.showMessageDialog(null, "File missing/invalid. Please check file");
			}			
		}
		
		public static String deserializeString(File file)
				throws IOException {
				    int len;
				    char[] chr = new char[4096];
				    final StringBuffer buffer = new StringBuffer();
				    final FileReader reader = new FileReader(file);
				    try {
				        while ((len = reader.read(chr)) > 0) {
				            buffer.append(chr, 0, len);
				        }
				    } finally {
				        reader.close();
				    }
				    return buffer.toString();
				}
}


